Skip to content

fix: add non-USB keyboard directly without VID/PID check - #716

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-368071-fix-non-usb-keyboard-not-displayed
Jul 30, 2026
Merged

fix: add non-USB keyboard directly without VID/PID check#716
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-368071-fix-non-usb-keyboard-not-displayed

Conversation

@add-uos

@add-uos add-uos commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

PS/2 and I2C keyboards in hwinfo use single-token Vendor/Device format (e.g. "Vendor: 0x0001") which cannot be parsed into VID/PID, causing addKeyboardDevice to drop them. Gate the VID/PID+lsusb verification to USB keyboards only; non-USB keyboards are appended directly.

PS/2、I2C 等内置键盘的 hwinfo 信息为 "Vendor: 0xNNNN" 单段格式,
无法解析出 VID/PID,导致 addKeyboardDevice 误删除。将 VID/PID+lsusb 校验限定为仅 USB 键盘,非 USB 键盘直接添加。

Log: 修复非USB键盘因缺少VID/PID无法显示的问题
PMS: BUG-368071
Influence: PS/2、I2C、蓝牙等内置键盘现在能正常显示在设备管理器中

Summary by Sourcery

Bug Fixes:

  • Prevent PS/2, I2C, Bluetooth and other non-USB keyboards from being incorrectly dropped due to missing VID/PID, allowing them to appear correctly in the device manager.

PS/2 and I2C keyboards in hwinfo use single-token Vendor/Device format
(e.g. "Vendor: 0x0001") which cannot be parsed into VID/PID, causing
addKeyboardDevice to drop them. Gate the VID/PID+lsusb verification
to USB keyboards only; non-USB keyboards are appended directly.

PS/2、I2C 等内置键盘的 hwinfo 信息为 "Vendor: 0xNNNN" 单段格式,
无法解析出 VID/PID,导致 addKeyboardDevice 误删除。将 VID/PID+lsusb
校验限定为仅 USB 键盘,非 USB 键盘直接添加。

Log: 修复非USB键盘因缺少VID/PID无法显示的问题
PMS: BUG-368071
Influence: PS/2、I2C、蓝牙等内置键盘现在能正常显示在设备管理器中
@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR ensures that only USB keyboards undergo VID/PID + lsusb verification, while non-USB keyboards (e.g., PS/2, I2C, Bluetooth) are appended directly, preventing them from being incorrectly dropped due to missing VID/PID information.

Sequence diagram for updated keyboard addition logic

sequenceDiagram
    participant DeviceManager
    participant DeviceInput

    DeviceManager->>DeviceInput: getInterface()
    DeviceInput-->>DeviceManager: interface
    alt [interface does not contain USB]
        DeviceManager->>DeviceManager: m_ListDeviceKeyboard.append(device)
        DeviceManager->>DeviceInput: qCDebug(appLog)
        DeviceManager->>DeviceInput: return
    else [interface contains USB]
        DeviceManager->>DeviceInput: getVID()
        DeviceInput-->>DeviceManager: vid
        DeviceManager->>DeviceInput: getPID()
        DeviceInput-->>DeviceManager: pid
        alt [vid.isEmpty() or pid.isEmpty()]
            DeviceManager->>DeviceInput: qCDebug(appLog)
            DeviceManager->>DeviceInput: deleteLater()
        else [valid VID/PID]
            DeviceManager->>DeviceManager: lsusb verification and append
        end
    end
Loading

File-Level Changes

Change Details Files
Gate VID/PID + lsusb verification logic to USB keyboards only and add non-USB keyboards directly.
  • Retrieve the device interface string and use it to determine whether the keyboard is USB or non-USB.
  • For non-USB keyboards, append the device directly to the keyboard list and log a debug message, then return early.
  • For USB keyboards with empty VID or PID, change behavior from allowing them through without verification to deleting the device and logging that it was not added.
deepin-devicemanager/src/DeviceManager/DeviceManager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new interface gate treats any device whose interface string is empty or does not contain USB as a non-USB keyboard; consider explicitly handling empty/unknown interfaces to avoid mistakenly adding ghost or misclassified devices.
  • Previously USB keyboards with empty VID/PID were still added with a debug note, but now they are dropped; double-check whether this behavior change is intentional and, if so, whether there are known USB devices that legitimately lack VID/PID and should be handled differently.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `interface` gate treats any device whose interface string is empty or does not contain `USB` as a non-USB keyboard; consider explicitly handling empty/unknown interfaces to avoid mistakenly adding ghost or misclassified devices.
- Previously USB keyboards with empty VID/PID were still added with a debug note, but now they are dropped; double-check whether this behavior change is intentional and, if so, whether there are known USB devices that legitimately lack VID/PID and should be handled differently.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了USB与非USB键盘设备的区分处理,修复了非USB键盘因无VID/PID被误删的问题。
逻辑严谨,注释清晰,内存管理得当,无安全漏洞。

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

代码在 DeviceManager::addKeyboardDevice 函数中,通过 device->getInterface() 获取接口类型,并使用 interface.contains("USB", Qt::CaseInsensitive) 进行判断。非USB设备直接添加至 m_ListDeviceKeyboard 列表并返回,避免了进入后续的VID/PID校验逻辑被误删;USB设备若无VID/PID则调用 deleteLater() 安全释放内存。逻辑分支清晰,条件判断准确。
潜在问题:无
建议:无

  • 2.代码质量(良好)✓

代码新增了详细的注释,解释了PS/2、I2C、蓝牙等内置键盘没有标准VID/PID的原因,以及为何需要直接添加,极大地提升了代码的可读性和可维护性。日志输出也从原先的 "adding keyboard device without verification" 修改为 "USB keyboard VID or PID is empty, device not added",更加准确地反映了实际处理逻辑。
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

仅增加了一次字符串获取和一次大小写不敏感的包含判断,时间复杂度为O(n),对整体性能影响微乎其微。没有引入不必要的循环或系统调用。
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码处理逻辑基于本地设备信息,不涉及外部不可信输入的解析与执行,不存在命令注入、路径遍历等风险。内存释放使用Qt标准的 deleteLater() 机制,避免了野指针和双重释放问题。

  • 建议:无

■ 【改进建议代码示例】

// 当前代码已足够完善,无需额外修复,保持原样即可。
void DeviceManager::addKeyboardDevice(DeviceInput *const device)
{
    QString vid = device->getVID();
    QString pid = device->getPID();
    QString interface = device->getInterface();

    // 仅USB键盘具备有效的VID/PID,需要通过lsusb校验以过滤无效/幽灵USB设备。
    // PS/2、I2C、蓝牙等内置键盘没有VID/PID(hwinfo中为 "Vendor: 0xNNNN" 单段格式,
    // 无法解析出VID/PID),应直接添加,避免被误删导致键盘无法显示。
    if (!interface.contains("USB", Qt::CaseInsensitive)) {
        m_ListDeviceKeyboard.append(device);
        qCDebug(appLog) << "Non-USB keyboard added directly, interface:" << interface;
        return;
    }

    if (vid.isEmpty() || pid.isEmpty()) {
        qCDebug(appLog) << "USB keyboard VID or PID is empty, device not added";
        device->deleteLater();
        return;
    }
    // ... 后续逻辑
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@add-uos

add-uos commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 3036935 into linuxdeepin:master Jul 30, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants